home *** CD-ROM | disk | FTP | other *** search
/ Openstep 4.2 (Developer) / Openstep Developer 4.2.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / unix.subproj / mail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-09  |  2.8 KB  |  122 lines

  1. /* mail.c
  2.    Send mail to a user.
  3.  
  4.    Copyright (C) 1992, 1993 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP package.
  7.  
  8.    This program is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU General Public License as
  10.    published by the Free Software Foundation; either version 2 of the
  11.    License, or (at your option) any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
  24.    */
  25.  
  26. #include "uucp.h"
  27.  
  28. #include "uudefs.h"
  29. #include "sysdep.h"
  30. #include "system.h"
  31.  
  32. #include <errno.h>
  33.  
  34. #if HAVE_TIME_H
  35. #include <time.h>
  36. #endif
  37.  
  38. #ifndef ctime
  39. extern char *ctime ();
  40. #endif
  41.  
  42. /* Mail a message to a user.  */
  43.  
  44. boolean
  45. fsysdep_mail (zto, zsubject, cstrs, paz)
  46.      const char *zto;
  47.      const char *zsubject;
  48.      int cstrs;
  49.      const char **paz;
  50. {
  51.   char **pazargs;
  52.   char *zcopy, *ztok;
  53.   size_t cargs, iarg;
  54.   FILE *e;
  55.   pid_t ipid;
  56.   time_t itime;
  57.   int i;
  58.  
  59.   /* Parse MAIL_PROGRAM into an array of arguments.  */
  60.   zcopy = zbufcpy (MAIL_PROGRAM);
  61.  
  62.   cargs = 0;
  63.   for (ztok = strtok (zcopy, " \t");
  64.        ztok != NULL;
  65.        ztok = strtok ((char *) NULL, " \t"))
  66.     ++cargs;
  67.  
  68.   pazargs = (char **) xmalloc ((cargs + 4) * sizeof (char *));
  69.  
  70.   memcpy (zcopy, MAIL_PROGRAM, sizeof MAIL_PROGRAM);
  71.   for (ztok = strtok (zcopy, " \t"), iarg = 0;
  72.        ztok != NULL;
  73.        ztok = strtok ((char *) NULL, " \t"), ++iarg)
  74.     pazargs[iarg] = ztok;
  75.  
  76. #if ! MAIL_PROGRAM_SUBJECT_BODY
  77.   pazargs[iarg++] = (char *) "-s";
  78.   pazargs[iarg++] = (char *) zsubject;
  79. #endif
  80.  
  81. #if ! MAIL_PROGRAM_TO_BODY
  82.   pazargs[iarg++] = (char *) zto;
  83. #endif
  84.  
  85.   pazargs[iarg] = NULL;
  86.  
  87.   e = espopen ((const char **) pazargs, FALSE, &ipid);
  88.  
  89.   ubuffree (zcopy);
  90.   xfree ((pointer) pazargs);
  91.  
  92.   if (e == NULL)
  93.     {
  94.       ulog (LOG_ERROR, "espopen (%s): %s", MAIL_PROGRAM,
  95.         strerror (errno));
  96.       return FALSE;
  97.     }
  98.  
  99. #if MAIL_PROGRAM_TO_BODY
  100.   fprintf (e, "To: %s\n", zto);
  101. #endif
  102. #if MAIL_PROGRAM_SUBJECT_BODY
  103.   fprintf (e, "Subject: %s\n", zsubject);
  104. #endif
  105.  
  106. #if MAIL_PROGRAM_TO_BODY || MAIL_PROGRAM_SUBJECT_BODY
  107.   fprintf (e, "\n");
  108. #endif
  109.  
  110.   (void) time (&itime);
  111.   /* Remember that ctime includes a \n, so this skips a line.  */
  112.   fprintf (e, "Message from UUCP on %s %s\n", zSlocalname,
  113.        ctime (&itime));
  114.  
  115.   for (i = 0; i < cstrs; i++)
  116.     fputs (paz[i], e);
  117.  
  118.   (void) fclose (e);
  119.  
  120.   return ixswait ((unsigned long) ipid, MAIL_PROGRAM) == 0;
  121. }
  122.